package hero_info

import (
	"go_server/game_server/dataconfig/config_manager"
	"go_server/game_server/protocol/pb"
	"go_server/zinx/ziface"
	"go_server/zinx/zlog"
)

// 添加默认英雄
func (s *Hero_info_service) S2C_AddDefHeros(conn ziface.IConnection, roleid int64) pb.ErrorCodeManager {
	hero := Hero_info_serviceObj.LoadByRoleId(roleid)

	//添加默认英雄数据
	defHeros := config_manager.GetStcTableHero_SheetHeroConfig_Default_UnlockStatus()
	if defHeros != nil {
		ids := make([]int32, 0)
		for i := 0; i < len(defHeros); i++ {
			dh := defHeros[i]
			ids = append(ids, dh.Id)
		}
		s.on_S2C_AddHero(hero, ids)
	}

	msgS2C := s.on_S2C_GetHeros(hero)
	if msgS2C != nil {
		zlog.Debugf("ProtocolManager_GetHeros %v", msgS2C)
		defer func() {
			conn.SendBuffPBMsg(uint32(pb.ProtocolManager_GetHeros), msgS2C)
		}()
	}

	defer func() {
		hero.SaveDB_HeroInfo_All()
	}()
	return pb.ErrorCodeManager_SUCCESS
}
